package com.yangjiayu.Controller;

import com.yangjiayu.service.ChatService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * @Classname HelloController
 * @Description TODO
 * @Date 2025/8/12 19:57
 * @Created by YangJiaYu
 */
@RestController
@RequestMapping("hello")
public class HelloController {

    @Resource
    private ChatService chatService;

//    http://localhost:8080/hello/world
    @GetMapping("/world")
    public String HelloController(){
        return "yangjiayu";
    }


    @GetMapping("chat")
    public String chat(String msg){
        return chatService.chatTest(msg);
    }

    @GetMapping("chat/stream/response")
    public Flux<ChatResponse> chatStreamResponse(String msg,HttpServletResponse response){
        response.setCharacterEncoding("UTF-8");
        return chatService.streamResponse(msg);
    }

    @GetMapping("chat/stream/str")
    public Flux<String>chatStreamStr(String msg, HttpServletResponse response){
        response.setCharacterEncoding("UTF-8");
        return chatService.streamStr(msg);
    }

}
